<?php
/**
 * 名称：NavModel
 * 描述：应用模型
 * 作者：sun 时间：2013-11-20
 * 版本号：V1.0.0
 */
class NavModel extends Model {
	var $tableName = 'nav';
	
	/**
	 * 获取头部导航
	 * @return array 头部导航
	 */
	public function getTopNav($no_login_show="0") {
		$map['status'] = 1;
		if($no_login_show !=="0"){
			$map['no_login_show'] = $no_login_show;
		}
		$list = M("nav") -> where($map) ->order("`order_sort`") -> select();
    	foreach ($list as $k => $v){
    		$list[$k]['url'] = empty($v['url']) ? 'javascript:;' : str_replace('{website}', SITE_URL, $v['url']);
    		if(intval($v['pid']) == 0){
    			$navlist[intval($v['id'])] = $list[$k];
    		}
    	}
    	foreach ($list as $k => $v){
    		if(intval($v['pid']) > 0){
    			$navlist[intval($v['pid'])]['child'][] = $v;
    		}
    	}
    	empty($topNav) && $topNav = array();
		return $navlist;
	}
}